<?php

namespace App\Http\Controllers\App;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Models\Queue;
use App\Models\Shop;
/**
 * 队列管理控制器
 */
class QueueController extends BaseController
{
    /**
     * 队列列表(GET) api/queue/quLists
     * 
     * @return json
     */
    public function quLists(Request $request)
    {   
        // 实例化
        $Queue  = new Queue;
        $Shop   = new Shop;

        // 查询列表
        $data = DB::table($Queue['table'].' as q')
                ->leftJoin($Shop['table'].' as s' , 'q.shop_id' , '=' , 's.id')
                ->select('q.id','name','min_amount','max_amount','day_amount','spec','poundage','q.status','max_total_amount','max_total_order','shopname')
                ->paginate($this->pageSize);

        return self::json($data,'查询成功');
    }

    /**
     * 队列编辑(POST) api/queue/upQueue
     *
     * @return json
     */
    public function upQueue(Request $request)
    {
        $id = $request->input('id');
        if(!$id){
            return self::error('参数不完整');
        }

        // 初始化数组
        $data = array();

        // 数据整理
        $request->input('max_total_amount')     == null || $data['max_total_amount']    = $request->input('max_total_amount');      // 最大交易额(后台控制）
        $request->input('max_total_order')      == null || $data['max_total_order']     = $request->input('max_total_order');       // 最高交易单数(后台控制)

        $re = Queue::where('id',$id)->update($data);

        if($re){

            return self::success('更新成功');

        }else{

            return self::error('更新失败');
            
        }   
    }

    

}
